package cn.stylefeng.guns.modular.system.warpper;

import cn.stylefeng.guns.core.common.constant.factory.ConstantFactory;
import cn.stylefeng.guns.modular.merchandise.service.IMerService;
import cn.stylefeng.guns.modular.system.model.Mer;
import cn.stylefeng.roses.core.base.warpper.BaseControllerWrapper;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.page.PageResult;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShoppingCartWrapper extends BaseControllerWrapper {

    @Autowired
    private IMerService merService;

    public ShoppingCartWrapper(Map<String, Object> single) {
        super(single);
    }

    public ShoppingCartWrapper(List<Map<String, Object>> multi) {
        super(multi);
    }

    public ShoppingCartWrapper(Page<Map<String, Object>> page) {
        super(page);
    }

    public ShoppingCartWrapper(PageResult<Map<String, Object>> pageResult) {
        super(pageResult);
    }

    @Override
    protected void wrapTheMap(Map<String, Object> map) {
        int id = Integer.parseInt(map.get("merid").toString());
        Map<String, Object> attrObj = new HashMap<>();
        if(ToolUtil.isNotEmpty(map.get("attr"))){
            Map<String, Object> attrMap = JSON.parseObject(map.get("attr").toString());
            attrMap.forEach((key, value) -> {
                attrObj.put(key, ConstantFactory.me().getDictName(Integer.parseInt(value.toString())));
            });
        }
        map.put("pictureURL",ConstantFactory.me().getMerPicture(id));
        map.put("attrObj", attrObj);
        map.put("merName",ConstantFactory.me().getMerName(id));
    }
}
